
<?
	   layout("/inc/win_layout.html",{title:sysTitle}){
    ?>

<div class="row">
		<div class="col-lg-12">
				<div class="panel" >
					<div class="panel-body pan " style="width:auto;height:auto;overflow: auto;">
						<form action="#" class="form-horizontal">
							<div class="form-body pal"
								style="float:left;width:100%; overflow: auto;">
								<input id="id" type="hidden" class="form-control" />
								<div id="guishu" style="margin-top:-8px; padding-bottom: 10px;">
									<label for="generalWordCategoryId" class="col-md-3 control-label">所属分类
										<span class='require'>*</span> </label>
									<div class="col-md-9">
										<div class="input-icon">
											<select id="generalWordCategoryId" class="form-control">
												
											</select>
										</div>
									</div>
								</div>

								<div style="padding-bottom: 10px;">
									<label for="wordName" class="col-md-4 control-label">
										<div align="right">
											词名称<span class='require' >*</span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordName" type="text" class="form-control" />
										</div>
									</div>
								</div>


								<div style="padding-bottom: 10px;">
									<label for="wordPinyin" class="col-md-4 control-label">
										<div align="right">
											汉语拼音 
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordPinyin" type="text" class="form-control" onchange="verify(this.value,this.id);"/>
										</div>
									</div>
								</div>

								<div style="padding-bottom: 10px;">
									<label for="wordEnglish" class="col-md-4 control-label">
										<div align="right">
											英文译名
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordEnglish" type="text" onchange="verify(this.value,this.id);" class="form-control" />
										</div>
									</div>
								</div>

								<div style="padding-bottom: 10px;">
									<label for="wordInitial" class="col-md-4 control-label">
										<div align="right">
											词首字母
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<input id="wordInitial" type="text"onchange="verify(this.value,this.id);" class="form-control" />
										</div>
									</div>
								</div>
								
								
								<div style="padding-bottom: 10px;">
									<label for="wordScopeNote" class="col-md-4 control-label">
										<div align="right">
											含义注释 <span class='require' ></span>
										</div> </label>
									<div class="col-md-8">
										<div class="input-icon">
											<textarea id="wordScopeNote"  rows="3" cols="20" class="form-control" ></textarea> 
										</div>
									</div>
								</div>
								
							</div>
						</form>
					</div>
				</div>
		</div>
</div>

<?} ?>
<script>
	var generalWordCategoryId = window.parent.getGWordCategoryId();
	var generalWordId = window.parent.getGeneralWordId();
	$("#id").val(generalWordId);
	$(function() {
		showXiaLaGWordCategory();
	});
	//验证
	function verify(verifyName,verifyId){
		var regu="[\u4e00-\u9fa5]";
		var re = new RegExp(regu);
		if (re.test(verifyName)) {
	        alert("输入不符合规则，请重新输入！");
	        $("#"+verifyId).val("");
   		 }
	}
	
	function Page() {
				if($.trim($("#generalWordCategoryId").val())==-1) {
		        	alert('请选择分类！');
		        	return null;
		        }
				if($.trim($("#wordName").val()).length<1) {
		        	alert('词名称不能为空！');
		        	return null;
		        }
		$.ajax({
			type : "post",
			url : "./generalWordAddEdit.do",
			data : {
				"id" : generalWordId,
				"generalWordCategoryId" : $("#generalWordCategoryId").val(),
				"wordName" : $("#wordName").val(),
				"wordPinyin" : $("#wordPinyin").val(),
				"wordEnglish": $("#wordEnglish").val(),
				"wordInitial" : $("#wordInitial").val(),
				"wordScopeNote" : $("#wordScopeNote").val(),
			},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.count>0){
					var index = parent.layer.getFrameIndex(window.name);
					window.parent.get();
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
	function demo1() {
		$.getJSON('./generalWordEditShow.do', {
			id : generalWordId,
			generalWordCategoryId : generalWordCategoryId
		//向服务端传的参数，此处只是演示
		}, function(res) {
			//此处仅仅是为了演示变化的内容
			selected("generalWordCategoryId", res[0].generalWordCategoryId);
			$("#wordName").val(res[0].wordName);
			$("#wordPinyin").val(res[0].wordPinyin);
			$("#wordEnglish").val(res[0].wordEnglish);
			$("#wordInitial").val(res[0].wordInitial);
			$("#wordScopeNote").val(res[0].wordScopeNote);
		});
	};
	
	function selected(selectname, selectid) {
		$("#" + selectname + " option").each(function() { //遍历全部option
			var v = $(this).val(); //获取option的内容
			if (v == selectid) {
				$(this).attr("selected", "selected");
			}
		});
	}
	
	
	function showXiaLaGWordCategory(){
		$.getJSON('./showXiaLaGeneralWordCategory.do',
						{
							"id" : generalWordId,
						},
						function(data) {
								$(data).each(
							function(n) {
								$("<option/>").html(data[n].categoryName).val(data[n].id)
										.appendTo("#generalWordCategoryId");
							});
							demo1();
						});
		}
	
	//汉字转拼音
  function pinYin(pinyinName){
		$.ajax({
			type : "post",
			url : "pinYin.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				$("#wordPinyin").val(data);
				$("#wordEnglish").val(data);
				
			},
			error : function(data) {
				alert("请求失败");
			}
		})
		}
	
</script>


